#要用俩个文件夹

import os
#1获取重命名的文件夹
import shutil

folder_name = '/home/xys/datasets/dataset_che/dataset-larger/JPEGImages/'
folder_name_xml = '/home/xys/datasets/dataset_che/dataset-larger/Annotations/'
save_jpg = '/home/xys/datasets/dataset_che/dataset-larger/img/'
save_xml = '/home/xys/datasets/dataset_che/dataset-larger/xml/'
#2获取文件夹中的文件名
file_names = os.listdir(folder_name)
file_names_xml = os.listdir(folder_name_xml)
p = '0'
#3对获取的名字重命名
for i,name in enumerate(file_names):
      file_front = name[0:-4]
      p = str(i)
      # shutil.copy(folder_name+name,save_jpg)
      origin_i = folder_name + name
      new_i = save_jpg + p +'.jpg'
      os.rename(origin_i,new_i)
      # shutil.copy(folder_name_xml+file_front+'.xml',save_xml)
      origin = folder_name_xml + file_front +'.xml'
      new = save_xml + p +'.xml'
      os.rename(origin, new)
